import type {
  PageResp,
  UserResponseDto,
  UpdateUserStatusDto,
  UserQueryParams,
  BatchUserOperationDto,
  ApiResponse
} from '@/types/api';
import request from '@/utils/request';

// 用户管理API
export const userApi = {
  // 获取用户列表 - 支持完整的查询参数
  getUsers: async (params?: UserQueryParams): Promise<PageResp> => {
    return await request.get('/admin/users', { params });
  },

  // 获取用户详情
  getUserDetail: async (id: string): Promise<UserResponseDto> => {
    return await request.get('/admin/users/detail', { params: { id } });
  },

  // 更新用户状态
  updateUserStatus: async (data: UpdateUserStatusDto): Promise<UserResponseDto> => {
    return await request.post('/admin/users/updateStatus', data);
  },

  // 批量更新用户状态
  batchUpdateStatus: async (userIds: string[], status: string): Promise<ApiResponse> => {
    return await request.post('/admin/users/batchUpdateStatus', { userIds, status });
  },

  // 批量操作用户
  batchOperation: async (data: BatchUserOperationDto): Promise<ApiResponse> => {
    return await request.post('/admin/users/batchOperation', data);
  },

  // 导出用户数据
  exportUsers: async (params?: UserQueryParams): Promise<Blob> => {
    return await request.get('/admin/users/export', {
      params,
      responseType: 'blob'
    });
  },

  // 搜索用户（模糊搜索）
  searchUsers: async (keyword: string, limit: number = 10): Promise<UserResponseDto[]> => {
    return await request.get('/admin/users/search', {
      params: { keyword, limit }
    });
  },

  // 获取用户统计信息
  getUserStats: async (): Promise<{
    total: number;
    active: number;
    inactive: number;
    banned: number;
    pending: number;
  }> => {
    return await request.get('/admin/users/stats');
  }
};

export type { UserQueryParams };
